package io.renren.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

// @Configuration
// public class CorsConfig implements WebMvcConfigurer {

    // @Override
    // public void addCorsMappings(CorsRegistry registry) {
    //     registry.addMapping("/**")
    //         .allowedOrigins("*")
    //         .allowCredentials(true)
    //         .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
    //         .maxAge(3600);
    // }
// }

// @Configuration
// public class CorsConfig {
//
//     @Bean
//     public CorsWebFilter corsWebFilter() {
//         UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//         CorsConfiguration configuration = new CorsConfiguration();
//         //配置跨域 Access-Control-Allow-Origin
//         configuration.addAllowedHeader("*");
//         //这里要写具体的跨域的前端url不要写*
//         configuration.addAllowedOrigin("http://localhost:8001");
//         configuration.addAllowedMethod("*");
//         configuration.setAllowCredentials(true);
//         source.registerCorsConfiguration("/**", configuration);
//         return new CorsWebFilter(source);
//     }
// }
